<style>
    .errorMessage{display:none;}
</style>
<div style="border:2px solid blue;padding:10px;">
<?php 
$model=new DepositRates; 
//Only if no <form>,to show Error tags and $model->validate() by JSON //.errorMessage
$model->addErrors(array(
            'currency_id' => array('empty'),
            'depo_min' => array('empty'),
            'depo_max' => array('empty'),
            'term' => array('empty'),
            'term_to' => array('empty'),
            'term_type' => array('empty'),
            'rate_value' => array('empty'),
        ));
?>

    <div class="name_param">Сумма:</div>
<table style="width:auto;"><tr><td>   
            
    <?php echo $form->textField($model, 'depo_min', array('value' => 'От', 'class' => 'small', 'style' => 'margin-right:14px;', 'onfocus' => "this.value=''")); ?>
    <?php echo $form->error($model, 'depo_min',array('style'=>'color:red')); ?>
</td><td>
    <?php echo $form->textField($model, 'depo_max', array('value' => 'До', 'class' => 'small', 'onfocus' => "this.value=''")); ?>
    <?php echo $form->error($model, 'depo_max',array('style'=>'color:red')); ?>
    
</td></tr><tr><td colspan="2">  
            
        <div class="name_param">Валюта</div>
        <div class="select_adjustment valuta">                              
            <?php echo $form->dropDownList($model, 'currency_id', CHtml::listData(Currencies::model()->findAll(), 'id', 'code'), array('id' => 'valuta', 'class' => 'jcalendar-select-val')); ?>
            <?php echo $form->error($model, 'currency_id',array('style'=>'color:red')); ?>                
        </div>
    
</td><tr><tr><td colspan="2">  
            
    <div class="name_param"><span class="name_sel">Срок,</span>
        <div class="select_adjustment valuta no_bord_bg">
            <?php echo $form->dropDownList($model, 'term_type', Deposits::model()->terms, array( 'id' => 'valuta4', 'class' => 'jcalendar-select-val','style'=>'width:50px;')); ?>
            <?php echo $form->error($model, 'term_type',array('style'=>'color:red')); ?>   
        </div>
    </div>

</td><tr><tr><td> 
            
    <?php echo $form->textField($model, 'term', array('value' => 'От', 'class' => 'small', 'style' => 'margin-right:14px;', 'onfocus' => "this.value=''")); ?>
    <?php echo $form->error($model, 'term',array('style'=>'color:red')); ?>
</td><td>
    <?php echo $form->textField($model, 'term_to', array('value' => 'До', 'class' => 'small', 'onfocus' => "this.value=''")); ?>
    <?php echo $form->error($model, 'term_to',array('style'=>'color:red')); ?>
    
</td></tr></table>
    
<div class="item item_sec">
    <div class="name_param">Процент:</div>
    <?php echo $form->textField($model, 'rate_value', array('class' => 'small', 'style' => '')); ?>
    <?php echo $form->error($model, 'rate_value',array('style'=>'color:red')); ?>
</div>
<div class="item">
    <a onclick="deposit_rate_form()" type="submit" class="green" href="javascript:void(0)"><i style="color:red;font-weight: bold;">+ Добавить</i></a>
</div>
<script type="text/javascript">
    function deposit_rate_form(){
        var model = {
            'currency_id' : $('#valuta').val(),
            'depo_min' : $('#DepositRates_depo_min').val(),
            'depo_max' : $('#DepositRates_depo_max').val(),
            'term_type' : $('#valuta4').val(),
            'term' : $('#DepositRates_term').val(),
            'term_to' : $('#DepositRates_term_to').val(),
            'rate_value' : $('#DepositRates_rate_value').val()
        };
        $.ajax({
            url: "/admin.php/banks/depositsrateajaxadd",
            type: "GET",
            data: ({ id : <?=$ins_id?>, DRform : JSON.stringify(model) }),
            contentType: "application/json; charset=utf-8",
            traditional: true,
            success: function(data) {
                  if (data.indexOf('{')==0) {//model->validation errors
                        //alert(data);//errors
                        $('.errorMessage').hide();
                        var Validation = eval('(' + data + ')');//jsonp
                        jQuery.each(Validation, function(key, value) {
                            $('input[name="DepositRates['+key+']"]').next().show().html(value);//show error tags
                            //except <select>, cos select tags have default value
                        });
                    } else {
                        $('.errorMessage').hide();
                        $("#depoBuf").append(data);
                    }
            },
            error: function(e) {
                alert('Error occured');
            }
        });
    }
    ///
        $(document).ready(function(e) {  
                if($("#valuta").length) $("#valuta").msDropDown();
                if($("#valuta4").length) $("#valuta4").msDropDown();
        });
        function delRate(id){
            $.ajax({
                url: "/banks/DepositsRateAjaxDel/"+id,
                success: function(data){
                    $("#itemRate"+id).remove();
                }
            });
        }
</script>
</div>